-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow connecting "url" and "title" attributes of the Image block to custom fields. #53488
Conversation
This pull request has changed or added PHP files. Please confirm whether these changes need to be synced to WordPress Core, and therefore featured in the next release of WordPress. If so, it is recommended to create a new Trac ticket and submit a pull request to the WordPress Core Github repository soon after this pull request is merged. If you're unsure, you can always ask for help in the #core-editor channel in WordPress Slack. Thank you! ❤️ View changed files❔ lib/experimental/blocks.php ❔ lib/experimental/connection-sources/index.php |
Size Change: +5.32 kB (0%) Total Size: 1.51 MB
ℹ️ View Unchanged
|
The block connections concept received a major overhaul. Now, blocks can be connected to custom fields and future data sources. This works in a 3-step process: - fetching connected block attributes - collecting values from connected sources, - and finally, updating the block's HTML with these values. A new helper function called 'gutenberg_render_block_with_connection_value' is introduced which replaces either the whole HTML tag or a specific attribute with the connection value, based on the source and configuration parameters. Also, adjusted the behavior in block-editor's custom fields when an attribute's value is empty. Instead of setting it as undefined, it is now set as an empty string, ensuring smoother handling.
ae153e8
to
4b7e904
Compare
@@ -7,7 +7,6 @@ | |||
"description": "Start with the basic building block of all narrative.", | |||
"keywords": [ "text" ], | |||
"textdomain": "default", | |||
"usesContext": [ "postId" ], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've removed it per this comment We can get the id from $post->ID
.
@SantosGuillamot I think this looks all right now, would be great if you could review it! I'm hesitant to make further improvements without consulting with Design. There are many obvious next improvements, but I'm not sure what path to take there. For example:
|
@@ -105,7 +105,7 @@ const withInspectorControl = createHigherOrderComponent( ( BlockEdit ) => { | |||
}, | |||
}, | |||
}, | |||
[ attributeName ]: undefined, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting this to undefined will remove the block content in the editor in the case of the Image block because an <img>
without src
is invalid markup. However, setting the url
to ''
(empty string) works.
Changing this back to draft because I'll add support for the Also, if an Image block has already populated the |
I've added support for the |
The most important fields on an image are going to be the URL and the |
I agree 🙂 Keep in mind that this was just an experiment to ensure it is possible to connect more than one attribute. Both will probably be available at some point. I encourage you to share any feedback in the tracking issue. |
Closing this as the experiment in this PR is largely irrelevant since the Block Bindings API will ship in WP 6.5 https://make.wordpress.org/core/2024/03/06/new-feature-the-block-bindings-api/ |
What?
Enable connecting the
url
attribute of the Image to custom fields.Related to #51373
Follow-up to #53241 and #53247.
Screencast
Very basic functionality can be demonstrated:
2023-08-09_20-01-41.mp4